<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Search extends Controller{
	var $title='search';
	var $view='search';
	
	function index(){
		include_once 'inc/Init.php';
		$kw=!isset($_POST['keyword']) ? '' : $_POST['keyword'];
		$type=!isset($_POST['type']) ? '' : $_POST['type'];
		if($kw==''){
			return goto_message('请输入关键字');			
		}
		else
		{
			$cond=myBase64Encode(myEscape($kw));
			$type=myBase64Encode(myEscape($type));
			$url='search.php?result/'.$kind_url.'/1/'.$type.'/'.$cond;
		 	header("Location:".$url."");
		}
	}
	
	function result(){
		include_once 'inc/Init.php';
		$this->load->library('pager');
		$this->load->database();
		$where=array('show'=>1);
		$page=intval($this->uri->segment(6,1));
		if($type=$this->uri->segment(7,1)){
			$type=myUnescape(myBase64Decode($type));
		}
		if($cond=$this->uri->segment(8,1)){
			$kw=myUnescape(myBase64Decode($cond));
			$this->db->like('title',$kw);
			$this->db->or_like('content',$kw);
		}
		$each=12;
		$this->pager->init(array(
			'table'=>$type,
			'link'=>site_url("{$this->title}/index/$kind_url/{page}"),
			'where'=>$where,
			'page'=>$page,
			'each'=>$each,
		));
		$this->db->select('*');
		$this->db->order_by("sort_id","desc");
		list($page_link,$data,$page,$total,$max_page)=$this->pager->create_link();
		$this->load->view($this->view,get_defined_vars());

	}
	
	
}